//
//  BuKeInforTopSearchView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/26.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "BuKeInforTopSearchView.h"

@implementation BuKeInforTopSearchView

- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        [self initSubView];
        [self layout];
    }
    return self;
}
- (void)initSubView{
//    [self addSubview:self.searchView];
//    [self addSubview:self.xianShangButton];
//    [self addSubview:self.xianXiaButton];
}
- (void)layout{
//    [_searchView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(self.mas_centerX).offset(100);
//        make.centerY.equalTo(self.mas_centerY);
//        make.width.equalTo(@400);
//        make.height.equalTo(@30);
//    }];
//    [_xianShangButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self->_searchView.mas_right).offset(40);
//        make.centerY.equalTo(self.mas_centerY);
//        make.width.equalTo(@80);
//        make.height.equalTo(@20);
//    }];
//    [_xianXiaButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self->_xianShangButton.mas_right).offset(40);
//        make.centerY.equalTo(self.mas_centerY);
//        make.width.equalTo(@80);
//        make.height.equalTo(@20);
//    }];
    __weak typeof(self) weakSelf = self;;
    _searchView.block = ^(NSString * _Nonnull keyStr) {
        [weakSelf shearchKeyStr:keyStr];
    };
    
}

- (void)shearchKeyStr:(NSString *)keyStr {
    self.searchView.searchTF.text = @"";
    if (self.block) {
        self.block(_keyStr,keyStr);
    }
}

- (LWQSearchView *)searchView{
    if (!_searchView) {
        LWQSearchView *search = [[LWQSearchView alloc]initWithFrame:CGRectMake(0,44, self.frame.size.width, 63) initWithType:0 andImageName:@"search_buke"];
        _searchView = search;
    }
    return _searchView;
}
- (UIButton *)xianShangButton{
    if (!_xianShangButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"  线上" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        [button setTitleColor:TITLECOLOR forState:UIControlStateNormal];
        [button addTarget:self action:@selector(xianShangClick:)
         forControlEvents:UIControlEventTouchUpInside];
        button.selected = NO;
        [button setImage:[UIImage imageNamed:@"fudao_normol"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"fudao_normol"] forState:UIControlStateHighlighted];
        [button setImage:[UIImage imageNamed:@"fudao_selected"] forState:UIControlStateSelected];
        _xianShangButton = button;
    }
    return _xianShangButton;
}
- (void)xianShangClick:(UIButton *)sender{
    _xianShangButton.selected = YES;
    _xianXiaButton.selected = NO;
    NSString *dowm = @"";
    if (sender.selected == YES) {
        dowm = @"1";
        
    }
    _keyStr = dowm;
    if (self.block) {

        self.block(dowm,@"");
//=======
//        self.block(0);
//>>>>>>> .r1510
    }
}
- (UIButton *)xianXiaButton{
    if (!_xianXiaButton){
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"  线下" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        button.selected = YES;
        [button setTitleColor:TITLECOLOR forState:UIControlStateNormal];
        [button addTarget:self action:@selector(xianXiaClick:) forControlEvents:UIControlEventTouchUpInside];
        [button setImage:[UIImage imageNamed:@"fudao_normol"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"fudao_normol"] forState:UIControlStateHighlighted];
        [button setImage:[UIImage imageNamed:@"fudao_selected"] forState:UIControlStateSelected];
        _xianXiaButton = button;
    }
    return _xianXiaButton;
}
- (void)xianXiaClick:(UIButton *)sender{
    sender.selected = !sender.selected;

    NSString *dowm = @"";
    if (sender.selected == YES) {
        dowm = @"0";
    }
    _keyStr = dowm;
//=======
    _xianXiaButton.selected = YES;
    _xianShangButton.selected = NO;
//>>>>>>> .r1510
    if (self.block) {

        self.block(dowm,@"");
//=======
//        self.block(1);
//>>>>>>> .r1510
    }
}
@end
